import * as THREE from 'three';
import {lon2xy} from "./math"
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
const loader = new GLTFLoader();
const flyGroup = new THREE.Group()
var mixer = null; //声明一个混合器变量
loader.load('fly.glb',(gltf)=>{
    flyGroup.add(gltf.scene)
    gltf.scene.traverse(function (child) {
        if (child.isMesh) {
            var material = child.material
            child.material = new THREE.MeshLambertMaterial({
                color: material.color,
            })
        }
    });
    var E = 121.49526536464691; //无人机经纬度坐标
    var N = 31.24189350905988;
    const xy = lon2xy(E, N)
    flyGroup.position.set(xy.x,xy.y,300)
    flyGroup.scale.set(5,5,5)
    flyGroup.rotateX(Math.PI/2)
     mixer = new THREE.AnimationMixer(gltf.scene);
    var AnimationAction = mixer.clipAction(gltf.animations[0]);
    AnimationAction.timeScale = 15; //默认1，可以调节播放速度
    AnimationAction.play();
})
var clock = new THREE.Clock();
function render(){
    if(mixer!== null){
        mixer.update(clock.getDelta())
    }
    requestAnimationFrame(render)
}
render()
export {
    flyGroup
}